package mysql

import (
	"gorm.io/gorm"
)

type ScenicSpot struct {
	gorm.Model
	ScenicSpotName     string  `gorm:"type:varchar(100);not null;comment:景区名"`
	ScenicSpotAddress  string  `gorm:"type:varchar(100);not null;comment:景区地址"`
	ScenicSpotDescribe string  `gorm:"type:varchar(255);not null;comment:景区描述"`
	Fare               float64 `gorm:"type:decimal(10,2);not null;comment:票价"`
	Stock              int     `gorm:"type:int(10);not null;comment:票余量"`
	StartTime          string  `gorm:"type:varchar(255);not null;comment:开园时间"`
	EndTime            string  `gorm:"type:varchar(255);not null;comment:闭园时间"`
	OpeningGarden      int     `gorm:"type:int(10);;not null;comment:开园状态1.已闭园 2.开园中"`
}

func (s ScenicSpot) ShowList() (result []*ScenicSpot, err error) {
	err = DB.Model(&ScenicSpot{}).Find(&result).Error
	return
}

func (s ScenicSpot) ShowInfo(id int64) (result *ScenicSpot, err error) {
	err = DB.Model(&ScenicSpot{}).Where("id=?", id).Limit(1).Find(&result).Error
	return
}

func (s ScenicSpot) DedStock(id int64, num int) error {
	return DB.Model(&ScenicSpot{}).Where("id=?", id).Limit(1).Update("stock", num).Error
}
